Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use TS Config presets to transpile correctly #325

Closed
wants to merge 3 commits into from

Conversation

alumni
Copy link

@alumni alumni commented Apr 19, 2024

Fixes #324

@alumni alumni force-pushed the fix/transpile-commonjs branch 2 times, most recently from a12ff86 to c837bda Compare April 19, 2024 13:46
@dubems
Copy link

dubems commented Jun 20, 2024

Thanks @alumni for making this fix.

Quick question: Is there a reason this is not merged yet? I'm currently having the same issue referenced in this PR, i:e #324

I'd also like to know if there is a workaround for this while this PR is not merged yet

cc: @jorgebodega

@jorgebodega
Copy link
Owner

I'm going to try to create a new PR with some changes of this one and some other changes, and merge this weekend.

And probably, those changes are going to be ported to https://github.com/jorgebodega/typeorm-factory as well

@jorgebodega
Copy link
Owner

jorgebodega commented Jun 22, 2024

Please, try the new version 7.1.0-next.1 and check if that works for all of you. If not, please comment here and we can try to find the solution together.

@alumni
Copy link
Author

alumni commented Jun 24, 2024

I'm getting this:

> ts-node -P ./tsconfig.json -r tsconfig-paths/register -T node_modules/@jorgebodega/typeorm-seeding/dist/cli.js xxx.seed.ts --dataSource ormconfig.ts
SeederImportationError: Could not load default seeders!
    at Command.run (/yyy/node_modules/.pnpm/@jorgebodega+typeorm-seeding@7.1.0-next.1_typeorm@0.3.20/node_modules/@jorgebodega/typeorm-seeding/src/commands/seed.command.ts:42:9)
    at async Command.parseAsync (/yyy/node_modules/.pnpm/commander@12.1.0/node_modules/commander/lib/command.js:1092:5)
    at async bootstrap (/yyy/node_modules/.pnpm/@jorgebodega+typeorm-seeding@7.1.0-next.1_typeorm@0.3.20/node_modules/@jorgebodega/typeorm-seeding/src/commands/seed.command.ts:79:2) {
  [cause]: TypeError: Unknown file extension ".ts" for /yyy/xxx.seed.ts
      at Object.getFileProtocolModuleFormat [as file:] (node:internal/modules/esm/get_format:160:9)
      at defaultGetFormat (node:internal/modules/esm/get_format:203:36)
      at defaultLoad (node:internal/modules/esm/load:143:22)
      at async ModuleLoader.load (node:internal/modules/esm/loader:396:7)
      at async ModuleLoader.moduleProvider (node:internal/modules/esm/loader:278:45)
      at async link (node:internal/modules/esm/module_job:78:21) {
    code: 'ERR_UNKNOWN_FILE_EXTENSION'
  }
}

@jorgebodega
Copy link
Owner

Can you give more information or create a minimal reproduction of the error?

@alumni
Copy link
Author

alumni commented Jul 15, 2024

@jorgebodega The issue that I see is in commandUtils.ts: loadDataSource is able to load ormconfig.ts correctly, but loadSeeders fails due to the dynamic import that is trying to load a typescript file, and somehow ts-node doesn't do anything about it.

In v6, the dynamic import was transpiled to a require which seemed to work, not sure why one works and the other not.

I'll try to investigate a bit more.

@alumni
Copy link
Author

alumni commented Jul 22, 2024

I will close this PR since this was fixed already in the main branch.

The issue that remains is that NodeJS can't dynamically import CommonJS modules (it's what loadSeeders is trying to do). This won't be fixed with a tsconfig option if we want to fix it for everybody.

TypeORM itself is using a utility function for supporting any kind of import: importOrRequireFile (in util/ImportUtils.ts).

@alumni alumni closed this Jul 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants